import moment from "moment"
import {dateAddZero} from "@/frame/utils/data-helper/add-zero.ts"

/**
 * 获取一天的时间
 */
export const getDayDate = () => {
    const beforeTime = Date.now() + 24 * 60 * 60 * 1000
    return {
        now: moment(beforeTime).format("YYYY-MM-DD"),
        before: moment(Date.now()).format("YYYY-MM-DD")
    }
}

/**
 * 获取昨天的时间
 */
export const getYesterdayDate = () => {
    const beforeTime = Date.now() - 24 * 60 * 60 * 1000
    return {
        now: moment(Date.now()).format("YYYY-MM-DD"),
        before: moment(beforeTime).format("YYYY-MM-DD")
    }
}

/**
 * 获取一周的时间 不包含
 */
export const getWeekDateNoContain = () => {
    const now = Date.now() + 24 * 60 * 60 * 1000
    const beforeTime = Date.now() - 24 * 60 * 60 * 1000 * 6
    return {
        now: moment(now).format("YYYY-MM-DD"),
        before: moment(beforeTime).format("YYYY-MM-DD")
    }
}

/**
 * 获取一周的时间
 */
export const getWeekDate = () => {
    const beforeTime = Date.now() - 24 * 60 * 60 * 1000 * 6
    return {
        now: moment().format("YYYY-MM-DD"),
        before: moment(beforeTime).format("YYYY-MM-DD")
    }
}

/**
 * 获取一月的时间
 */
export const getMonthDate = () => {
    const currentTime = new Date().getFullYear() + "-" + dateAddZero(new Date().getMonth() + 2) + "-01"
    const beforeTime = new Date().getFullYear() + "-" + dateAddZero(new Date().getMonth() + 1) + "-01"
    return {
        now: currentTime,
        before: beforeTime
    }
}

/**
 * 获取一年的时间
 */
export const getYearDate = () => {
    const currentTime = new Date().getFullYear() + 1
    const beforeTime = new Date().getFullYear()
    return {
        now: currentTime,
        before: beforeTime
    }
}